// EMERGENT GAME TECHNOLOGIES PROPRIETARY INFORMATION
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Emergent Game Technologies and may not 
// be copied or disclosed except in accordance with the terms of that 
// agreement.
//
//      Copyright (c) 1996-2008 Emergent Game Technologies.
//      All Rights Reserved.
//
// Emergent Game Technologies, Chapel Hill, North Carolina 27517
// http://www.emergent.net

#ifndef GNEBMMACROS_H
#define GNEBMMACROS_H

#define GnDeclareEBM(libname, entry) \
class entry libname##EBM \
	{ \
		public: \
		libname##EBM(); \
		static void Startup(); \
		static void Shutdown(); \
		protected: \
		static bool msInitialized; \
	}; 

#define GnImplementEBMConstructor(libname, dependencies) \
	bool libname##EBM::msInitialized = false; \
	libname##EBM::libname##EBM() \
	{ \
		static int siCounter = 0; \
		if (siCounter++ == 0) \
		{ \
			GnEngineBegingManager::AddLibrary(#libname, dependencies, \
			libname##EBM::Startup, libname##EBM::Shutdown); \
		} \
	}

#define GnImplementDllMain(libname) \
	HMODULE g_##libname##Handle = 0; \
	BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReason, LPVOID lpReserved)\
	{ \
		switch (ulReason) \
		{ \
			case DLL_PROCESS_ATTACH: \
				g_##libname##Handle = hModule; \
				GnEngineBegingManager::ProcessAccumulatedLibraries(); \
				break; \
			case DLL_PROCESS_DETACH: \
				g_##libname##Handle = 0; \
				GnEngineBegingManager::RemoveLibrary(#libname); \
				break; \
		} \
		return TRUE; \
	 }

#endif  // #ifndef GNEBMMACROS_H
